package com.wanmait.meteor.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.meteor.mapper.ManagerMapper;
import com.wanmait.meteor.pojo.Manager;
import com.wanmait.meteor.service.ManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class ManagerServiceImpl implements ManagerService {
    @Resource
    private ManagerMapper managerMapper;

    @Override
    public Manager findById(Integer id) {
        return null;
    }

    //金  查看数据库是否有此管理员账号
    @Override
    public Manager login(Manager manager) {
        return managerMapper.checkManager(manager);
    }

    @Override
    public boolean checkCode(String code, HttpServletRequest request) {
        HttpSession session = request.getSession();
        String sessionCode = (String) session.getAttribute("code");
        if (sessionCode.equalsIgnoreCase(code)){
            return true;
        }
        else{
            return false;
        }
    }

    @Override
    public boolean checkManagerPhone(String managerPhone){
        boolean flag = managerMapper.checkManagerPhone(managerPhone);
        return flag;
    }

    @Override
    public Boolean checkManagerAccount(String managerAccount) {
        boolean flag = managerMapper.checkManagerAccount(managerAccount);
        return flag;
    }

    @Override
    public PageInfo<Manager> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Manager> managers = managerMapper.allManager();
        PageInfo<Manager> pageInfo = new PageInfo<>(managers,11);
        return pageInfo;

    }

    @Override
    public int getPageSize(String str) {
        return managerMapper.getPageSize(str);
    }

    @Override
    public void addManager(Manager manager) {
        manager.setManagerType(false);
        managerMapper.addManager(manager);
    }

    @Override
    public void insert(Manager manager) {

    }

    @Override
    public List<Manager> findAll() {
        return null;
    }

    @Override
    public void update(Manager manager) {

    }
}
